﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QUT.Bio.Util;

namespace QUT.Bio.Map2D {
	/// <summary>
	/// A LabelledVertex represents a glyph with a textual label.
	/// </summary>
	
	public partial class LabelledVertex : UserControl {
		private string label;
		private FrameworkElement glyph;

		/// <summary>
		/// Constructor( glyph ). Adds the supplied glyph to the control and positions
		/// the label relative to the glyph
		/// </summary>
		/// <param name="glyph">The glyph representing the node.</param>
		
		public LabelledVertex( FrameworkElement glyph ) {
			this.glyph = glyph;

			InitializeComponent();

			SizeChanged += delegate( object sender, SizeChangedEventArgs args ) {
				textBlock.Margin = new Thickness( 0, 0, glyph.Width * 0.75, 0 );
			};

			LayoutRoot.Children.Add( glyph );
			glyph.SetRow( 1 );
			glyph.SetColumn( 0 );
			glyph.HorizontalAlignment = HorizontalAlignment.Right;
		}

		/// <summary>
		/// Default constructor, renders a labelled ellipse.
		/// </summary>

		public LabelledVertex()
			: this( new Ellipse {
				HorizontalAlignment = HorizontalAlignment.Right,
				Width = 5,
				Height = 5,
				Fill = new SolidColorBrush( Colors.Magenta )
			} ) {
		}

		/// <summary>
		/// Get or set the label.
		/// </summary>
		
		public string Label {
			get {
				return label;
			}
			set {
				textBlock.Text = label = value;
			}
		}
		
		/// <summary>
		/// Get the glyph.
		/// </summary>

		public FrameworkElement Glyph {
			get {
				return glyph;
			}
		}

		/// <summary>
		/// Get the textblock that renders the label, permitting advanced manipulation of the appearance of the vertex.
		/// </summary>

		public TextBlock TextBlock {
			get {
				return textBlock;
			}
		}
	}
}
